package wqlspringboot.springbootcrud.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wqlspringboot.springbootcrud.cv.JieGuo;
import wqlspringboot.springbootcrud.dao.UserDao;
import wqlspringboot.springbootcrud.entity.User;
import wqlspringboot.springbootcrud.service.UserService;

import java.util.List;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/17 20:55
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public PageInfo<User> findByPage(int current, int pageSize) {
        PageHelper.startPage(current,pageSize);
        List<User> all = userDao.findAll();
        PageInfo<User> info = new PageInfo<>(all);
        return info;
    }

    @Override
    public JieGuo addUser(User user) {
        int i = userDao.addUser(user);
            return new JieGuo(200,"添加成功");
    }

    @Override
    public JieGuo deleteById(Integer id) {
        userDao.deleteById(id);
        return new JieGuo(200,"删除成功");
    }

    @Override
    public JieGuo update(User user) {
       userDao.update(user);
       return new JieGuo(200,"修改成功");
    }
}
